﻿/// <reference path="../../Scripts/jquery/jquery-1.4.1-vsdoc.js" />

var avlmsg = "";
var avlitem = "";
$(function () {

    InitializeAvl();

    prm.add_endRequest(function (s, a) {
        InitializeAvl();
        if (a.get_error() != undefined) {
            CallOM(a.get_error().message);
            a.set_errorHandled(true);
        }
        else {
            CallOM(avlmsg);
        }

    });

    $('.canceleventbutton').click(CancelEvent);
});

function CancelEvent() {
    if (confirm("真的要取消参加此活动吗？")) {
        $.ajax({
        type : 'POST',
         url : relRootPath + "/Mod/Events/EventServices.asmx/CancelParticipateEvent",
        data: { eventId: eventId, userId: userid },
        context: {userId: userid},
        success: CancelSuccess
        });
    }
}

function CancelSuccess(d, s, x)
{
    var success = eval($(d).text());
    if (!success) {
        alert("网络问题，请稍后再试。");
    }
    else {
        $('#tb-parts div[uid=' + this.userId + ']').remove();
        $('#signupbox').remove();
        alert("已经取消参加活动。");
    }
}

function InitializeAvl() {
    $('a[rel=cancelsignup]').click(function() {
        //avlmsg = "你已经退出这次活动。";
    });
}

function AddFavorite(eid) {
    var f = new GenericFavorite();
    var success = f.AddFav("UserEvent", eid, userid, "");
    if (!success) {
        alert("未知错误，抱歉。");
    }
    else {
        location.reload();
    }
}

function DeleteFavorite(eid) {
    var f = new GenericFavorite();
    var success = f.DelFav("UserEvent", eid, userid);
    if (!success) {
        alert("未知错误，抱歉。");
    }
    else {
        location.reload();
    }
}